Fix zero init of struct WAY (again).
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 9 Apr 2004 16:13:37 +0000 (16:13 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 9 Apr 2004 16:13:37 +0000 (16:13 +0000)
1) snlen suboption  now allows forced shortname lengths.
2) snwhite suboption now allows generated shortnames to contain
        no whitespace.
3) icons are now mapped by geocache type, just as with Mapsource.
4) Waypoint comment now contains difficulty and terrain when available.
5) I added ascii dump of data written to the Garmins in addition to hex.

gpsbabel/Makefile
gpsbabel/garmin.c
gpsbabel/jeeps/gpsmem.c
gpsbabel/jeeps/gpssend.c
gpsbabel/testo

index e41dbd80cbbb75e5b2488ff0d8c084b6385a4db4..c94be63840211321f5a334021b416a8985812024 100644 (file)
@@ -78,8 +78,8 @@ dep:
        (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)' ) >> /tmp/dep
        echo Edit Makefile and bring in /tmp/dep
 
-VERSIONU=1_2_3_beta04052004
-VERSIOND=1.2.3_beta04052004
+VERSIONU=1_2_3_beta04072004
+VERSIOND=1.2.3_beta04072004
 #VERSIONU=1_2_2
 #VERSIOND=1.2.2
 
index adc891c2cbd9675b25acef40620d7b30441b9fd3..c33d654edf6650363e381bcf45b95fd5409a7630 100644 (file)
@@ -34,11 +34,18 @@ static GPS_PTrack *tx_tracklist;
 static GPS_PTrack *cur_tx_tracklist_entry;
 static char *getposn;
 static char *poweroff;
+static char *snlen;
+static char *snwhiteopt;
 
 static
 arglist_t garmin_args[] = {
-       { "get_posn", &getposn, "Return current position as a waypoint", ARGTYPE_BOOL},
-       { "power_off", &poweroff, "Command unit to power itself down", ARGTYPE_BOOL},
+       { "snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT },
+       { "snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames",
+               ARGTYPE_BOOL},
+       { "get_posn", &getposn, "Return current position as a waypoint", 
+               ARGTYPE_BOOL},
+       { "power_off", &poweroff, "Command unit to power itself down", 
+               ARGTYPE_BOOL},
        { 0, 0, 0, 0}
 };
 
@@ -114,7 +121,17 @@ rw_init(const char *fname)
                        break;
                        
        }
-       setshort_length(mkshort_handle, short_length);
+       /*
+        * If the user provided a short_length, override the calculated value.
+        */
+       if (snlen)
+               setshort_length(mkshort_handle, atoi(snlen));
+       else
+               setshort_length(mkshort_handle, short_length);
+
+       if (snwhiteopt)
+               setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt));
+
        setshort_mustupper(mkshort_handle, 1);
 
 }
@@ -373,6 +390,7 @@ waypoint_write(void)
        extern queue waypt_head;
        GPS_PWay *way;
        extern int32 gps_save_id;
+       int icon;
 
        way = xcalloc(n,sizeof(*way));
 
@@ -385,6 +403,7 @@ waypoint_write(void)
                waypoint *wpt;
                char *ident;
                char *src = NULL;
+               char obuf[256];
 
                wpt = (waypoint *) elem;
 
@@ -403,12 +422,24 @@ waypoint_write(void)
                        xfree(ident);
                }
                way[i]->ident[sizeof(way[i]->ident)-1] = 0;
-               if (src && strlen(src)) {
-                       memcpy(way[i]->cmnt, src, strlen(src));
+
+               if (wpt->gc_data.diff && wpt->gc_data.terr) {
+                       snprintf(obuf, sizeof(obuf), "%d/%d %s", 
+                                       wpt->gc_data.diff, wpt->gc_data.terr, 
+                                       src);
+                       memcpy(way[i]->cmnt, obuf, strlen(obuf));
+               } else  {
+                       memcpy(way[i]->cmnt, obuf, strlen(src));
                }
                way[i]->lon = wpt->longitude;
                way[i]->lat = wpt->latitude;
-               way[i]->smbl = mps_find_icon_number_from_desc(wpt->icon_descr, PCX);
+
+               if (get_cache_icon(wpt)) {
+                       icon = mps_find_icon_number_from_desc(get_cache_icon(wpt), PCX);
+               } else {
+                       icon = mps_find_icon_number_from_desc(wpt->icon_descr, PCX);
+               }
+               way[i]->smbl = icon;
                if (wpt->altitude != unknown_alt) {
                        way[i]->alt = wpt->altitude;
                }
index 48bc461af925b2984d1b423693b4e5bb5cf1d226..0ba1ec59c51380c31282b6271a439b1d1f5bc007 100644 (file)
@@ -225,7 +225,7 @@ GPS_PWay GPS_Way_New(void)
     GPS_PWay ret;
     int32 i;
     
-    if(!(ret=(GPS_PWay)malloc(sizeof(GPS_OWay))))
+    if(!(ret=(GPS_PWay)xcalloc(sizeof(GPS_OWay),1)))
     {
        perror("malloc");
        fprintf(stderr,"GPS_Way_New: Insufficient memory");
@@ -233,10 +233,19 @@ GPS_PWay GPS_Way_New(void)
        return NULL;
     }
 
+    /*
+     * It turns out that the Way struct, initialized with zeros (not the
+     * random stuff that we got with malloc, but REALLY initialized with
+     * zeros from the calloc above actually does use C strings and it's
+     * up to the various way_blah_send functions to zero/string pad things
+     * as it goes.   So neutralize this.
+     */
+#if 0
+
     /* 
      * Mark all as "unused".  These appear in the same order as in the struct.
      */
-#define BLANK(x)  memset(x, ' ',sizeof(x))
+#define BLANK(x)   memset(x, ' ',sizeof(x))
     BLANK(ret->ident);
     BLANK(ret->cmnt);
     BLANK(ret->wpt_ident);
@@ -257,6 +266,7 @@ GPS_PWay GPS_Way_New(void)
     ret->facility[0] = 0;
     ret->addr[0] = 0;
     ret->wpt_ident[0] = 0;
+#endif
     
     ret->lat = ret->lon = GPS_FLTMAX;
     ret->dst = 0;
index bf7ad86f0c10208dbf3c44860f80ce61ab16fb36..767d921e6523e3dd16316016ea92ade0181d559a 100644 (file)
@@ -100,6 +100,17 @@ Diag(void *buf, size_t sz)
        }
 }
 
+void 
+DiagS(void *buf, size_t sz)
+{
+       unsigned char *cbuf = (unsigned char *) buf;
+
+       while (sz--) {
+               unsigned char c = *cbuf++;
+               GPS_Diag("%c", isalnum(c) ? c : '.');
+       }
+}
+
 /* @func GPS_Write_Packet ***********************************************
 **
 ** Forms a complete packet to send 
@@ -143,6 +154,11 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet)
 
 
     Diag(&packet->chk, 3);
+
+    GPS_Diag(": ");
+    DiagS(packet->data, packet->bytes);
+    DiagS(&packet->chk, 3);
+
     if((ret=GPS_Serial_Write(fd,(const void *)&packet->chk,(size_t)3)) == -1)
     {
        perror("write");
index 5d389c016c292bb953824258c0de8c39218ef76a..068822adf805dea8326fa9098cd980d2146728e0 100755 (executable)
@@ -1,3 +1,5 @@
+GPSBABEL_FREEZE_TIME=y
+export GPSBABEL_FREEZE_TIME
 
 PNAME=${PNAME:-./gpsbabel}
 DIFF=${DIFF:-diff}